/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ingreso.java
 *
 * Created on 29-jun-2011, 23:18:26
 */

package adminasistencia;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;

/**
 *
 * @author micael
 */
public class ingreso extends javax.swing.JFrame {
    

    /** Creates new form ingreso */
    public ingreso() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        runText = new javax.swing.JTextField();
        nombreText = new javax.swing.JTextField();
        apellidoPText = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        fechaNacimientoText = new datechooser.beans.DateChooserCombo();
        jLabel7 = new javax.swing.JLabel();
        departamentosCombo = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        areaCombo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        passText = new javax.swing.JTextField();
        lugarCombo = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        apellidoMText = new javax.swing.JTextField();
        cargoText = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        anexoText = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        tipoCombo = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        correoText = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(600, 600));
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("INGRESO FUNCIONARIOS");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 30, -1, -1));

        jLabel2.setText("Nombre");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 110, -1, 20));

        jLabel3.setText("Apellido Paterno");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 140, -1, 20));

        jLabel4.setText("Contraseña");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 440, -1, 20));

        jLabel5.setText("RUT");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 80, -1, 20));
        getContentPane().add(runText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 80, 140, 20));
        getContentPane().add(nombreText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 110, 140, 20));
        getContentPane().add(apellidoPText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 140, 140, 20));

        jLabel6.setText("Fecha Nacimiento");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 200, -1, 20));

        fechaNacimientoText.setCurrentView(new datechooser.view.appearance.AppearancesList("Light",
            new datechooser.view.appearance.ViewAppearance("custom",
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("DejaVu Sans", java.awt.Font.PLAIN, 13),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("DejaVu Sans", java.awt.Font.PLAIN, 13),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    true,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("DejaVu Sans", java.awt.Font.PLAIN, 13),
                    new java.awt.Color(0, 0, 255),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("DejaVu Sans", java.awt.Font.PLAIN, 13),
                    new java.awt.Color(128, 128, 128),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("DejaVu Sans", java.awt.Font.PLAIN, 13),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("DejaVu Sans", java.awt.Font.PLAIN, 13),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(255, 0, 0),
                    false,
                    false,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                (datechooser.view.BackRenderer)null,
                false,
                true)));
    fechaNacimientoText.setFieldFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10));
    getContentPane().add(fechaNacimientoText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 200, 140, 20));

    jLabel7.setText("Area");
    getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 260, -1, 20));

    departamentosCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Contratos", "Maquinaria", "Conservacion" }));
    departamentosCombo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            departamentosComboActionPerformed(evt);
        }
    });
    getContentPane().add(departamentosCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 230, 140, 20));

    jLabel8.setText("Departamento");
    getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 230, -1, 20));

    areaCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RRHH", "BIENES", "FINANZAS" }));
    getContentPane().add(areaCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 260, 140, 20));

    jLabel9.setText("Apellido Materno");
    getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 170, -1, 20));
    getContentPane().add(passText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 440, 140, 20));

    lugarCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Valparaíso", "Con Con" }));
    getContentPane().add(lugarCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 290, 140, 20));

    jLabel10.setText("Lugar Trabajo");
    getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 290, -1, 20));
    getContentPane().add(apellidoMText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 170, 140, 20));
    getContentPane().add(cargoText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 320, 140, 20));

    jLabel11.setText("Cargo");
    getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 320, -1, 20));
    getContentPane().add(anexoText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 350, 140, 20));

    jLabel12.setText("Anexo");
    getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 350, -1, 20));

    jLabel13.setText("E-mail");
    getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 380, -1, 20));

    tipoCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Funcionario", "Convenio", "Honorario", "Practicante", "Administrador" }));
    getContentPane().add(tipoCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 410, 140, 20));

    jButton1.setText("GUARDAR");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });
    getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 480, 140, 50));
    getContentPane().add(correoText, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 380, 140, 20));

    jLabel14.setText("Tipo");
    getContentPane().add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 410, -1, 20));

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void departamentosComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_departamentosComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_departamentosComboActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int run = Integer.parseInt(runText.getText());
        String nombre = nombreText.getText();
        String apellidoP = apellidoPText.getText();
        String apellidoM = apellidoMText.getText();
        int departamento = this.departamentosCombo.getSelectedIndex();
        int area = this.areaCombo.getSelectedIndex();
        int lugar = this.lugarCombo.getSelectedIndex();
        int tipo = this.tipoCombo.getSelectedIndex();
        String cargo = cargoText.getText();
        int anexo = Integer.parseInt(anexoText.getText());
        String correo = correoText.getText();
        int pass = Integer.parseInt(passText.getText());
        String recibeDia, recibeMes, recibeAno, fecha;



        //El siguiente if es para dar el formato a la fecha
        if(fechaNacimientoText.getText().length()==7){//Si el largo de la fecha es 7 se da el siguinete formato
        recibeDia=fechaNacimientoText.getText().substring(0,1);// esto se da porque el dia tiene un largo de 2
        recibeMes = fechaNacimientoText.getText().substring(2,4);
        recibeAno = fechaNacimientoText.getText().substring(5,7);
        fecha= "20" + recibeAno + "-" + recibeMes + "-0" + recibeDia;

        }else{
            recibeDia = fechaNacimientoText.getText().substring(0,2);
            recibeMes = fechaNacimientoText.getText().substring(3,5);
            recibeAno = fechaNacimientoText.getText().substring(6,8);
            fecha= "20" + recibeAno + "-" + recibeMes + "-" + recibeDia;

            consultas con = new consultas();
            try {
                con.guardar_registro(run, nombre, apellidoP, apellidoM, departamento, area, lugar, tipo, cargo, anexo, correo, fecha, pass);
            } catch (SQLException ex) {
                Logger.getLogger(ingreso.class.getName()).log(Level.SEVERE, null, ex);
            }
            dispose();

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ingreso().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField anexoText;
    private javax.swing.JTextField apellidoMText;
    private javax.swing.JTextField apellidoPText;
    private javax.swing.JComboBox areaCombo;
    private javax.swing.JTextField cargoText;
    private javax.swing.JTextField correoText;
    private javax.swing.JComboBox departamentosCombo;
    private datechooser.beans.DateChooserCombo fechaNacimientoText;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JComboBox lugarCombo;
    private javax.swing.JTextField nombreText;
    private javax.swing.JTextField passText;
    private javax.swing.JTextField runText;
    private javax.swing.JComboBox tipoCombo;
    // End of variables declaration//GEN-END:variables

}
